package client.logic;

import packets.server.UserDetails;
import packets.server.UserList;
import client.gui.frmChatFrame;
import client.gui.frmMainFrame;

/**
 * Class to communicate with the gui layer 
 */
public class GuiFacade {

	private static GuiFacade instance;
	private frmMainFrame _mainFrame;

	/**
	 * Creates an instance of GuiFacade
	 * @param m	the main application frame which the facade should communicate with
	 */
	private GuiFacade(frmMainFrame m){
		_mainFrame = m;
	}

	/**
	 * 
	 * @return an instance of GuiFacade
	 */
	public static GuiFacade getInstance() {
		if (instance == null){
			frmMainFrame m = new frmMainFrame();
			m.setVisible(true);
			instance = new GuiFacade(m);
		}
		return instance;
	}
	
	/**
	 * initializes the GuiFacade
	 * @param m the main frame which this facade shuold communicate with
	 */
	public static void init(frmMainFrame m){
		instance = new GuiFacade(m);
	}

	/**
	 * shows the registration panel in the main frame
	 */
	public void showRegister() {
		_mainFrame.changeToRegister();
	}

	/**
	 * shows the login panel in the main frame
	 */
	public void showLogin() {
		_mainFrame.changeToLogin();
	}

	/**
	 * shows the user panel in the main frame
	 */
	public void showMainScreen() {
		_mainFrame.changeToMainScreen();
	}

	/**
	 * shows the user details panel in the main frame
	 * @param user the user's details to display
	 */
	public void showUserDetails(UserDetails user) {
		_mainFrame.changeToDetailsScreen(user);
	}

	/**
	 * shows the all-users panel , which displays a list of users
	 * and gives the option to see their details
	 * @param users the list of users to display
	 */
	public void showAllUsers(UserList users) {
		_mainFrame.changeToAllUsers(users);
	}

	/**
	 * shows the all-users panel , which displays a list of users
	 * and gives the option to chat with them
	 * @param users the list of users to display
	 */
	public void showWhoIsOnline(UserList users) {
		_mainFrame.changeToWhosOnline(users);
	}

	/**
	 * displays an error message window to the screen , and shows a message 
	 * @param msg the message to show
	 */
	public void showErrorMessage(String msg){
		_mainFrame.showErrorMessage(msg);
	}

	/**
	 * shows a message to a chat window
	 * @param chatFrame the frame to send the message to
	 * @param message the message to show
	 */
	public void recieveMessage(frmChatFrame chatFrame, String message) {
		chatFrame.recieveMessage(message);
	}

	/**
	 * closes a chat window
	 * @param chatFrame the frame to close
	 */
	public void closeChatWindow(frmChatFrame chatFrame) {
		chatFrame.dispose();
	}
}
